#include "Blocks/FenceBlock.h"
#include "Blocks/FenceGateBlock.h"
#include "Managers/BlocksManager.h"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{

    FenceBlock::FenceBlock()
    {
        addInheritance(this);
        addInheritance((IPaintableBlock*)this);
    }

    void FenceBlock::initialize() {}

    void FenceBlock::getCreativeValues(std::vector<int32_t> &blockVec)
    {
        blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetColor(0, -1)));
        for(int32_t index = 0; index < 16; ++index)
        {
            blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetColor(0, index)));
        }
    }
    void FenceBlock::getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues)
    {
		int32_t data = SetVariant(Terrain::ExtractData(oldValue), 0);
        dropValues.push_back(BlockDropValue { Terrain::MakeBlockValue(getIndex(), 0, data), 1 });
    }

    int32_t FenceBlock::getPaintColor(int32_t value)
    {
        return GetColor(Terrain::ExtractData(value));
    }
    int32_t FenceBlock::paint(int32_t value, int32_t color)
    {
        return Terrain::MakeBlockValue(getIndex(), 0, SetColor(Terrain::ExtractData(value), color));
    }

	bool FenceBlock::shouldConnectTo(int32_t value)
	{
		int32_t num = Terrain::ExtractContents(value);
		Block *block = GameSingleton::blocksManager->blocks[num];
		if(block->isBlock<FenceBlock*>() == false)
		{
			return block->isBlock<FenceGateBlock*>() == true;
		}
		return true;
	}

} // namespace PocketSurvival
